#! /bin/sh
#
# Fetch rules and targets prior for the "r2c" benchmark.
#
# rule_dir: input/golang.yaml
# target_dir: input/govwa
#
# See ../r2c-rules for centralized copy of the rule
# Uses sh because bash is not installed within the semgrep docker container.
#
set -eu

mkdir -p input

cp ../r2c-rules/golang.yml input/
cd input

# Obtain a shallow clone of a git repo for a specific commit
shallow_clone() {
  if [ -d "$name" ]; then
    echo "Reusing repo '$name'"
  else
    echo "Obtaining a shallow clone of git repo '$name', commit $commit"
    mkdir -p "$name"
    (
      cd "$name"
      git init
      git remote add origin "$url"
      git fetch --depth 1 origin "$commit"
      git checkout FETCH_HEAD -b tmp
    )
  fi
}

# Targets using other repos we run in CI
name="govwa"
url="https://github.com/0c34/govwa"
commit="59c1b725bc562aea279b8eeb9af440c6ad41d69d"
shallow_clone
